using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Pacman.Simulator
{
	class Program
	{
		private static Visualizer visualizer;
		private static Thread visualizerThread;
        static bool running = true;
		static void Main(string[] args) {
            try
            {
                string controllerName = "SmartDijkstraPac";
                startVisualizer(controllerName);
                Console.Title = "PACMAN SIMULATOR";
                Console.WriteLine("Simulator started");
                while (running)
                {
                    Console.Write(":>");
                    string input = Console.ReadLine();
                    switch (input)
                    {
                        case "exit":
                        case "quit":
                            running = false;
                            if (visualizer.Visible)
                                Console.WriteLine("Close the simulator to complete exit process");
                            break;
                        case "restart":
                        case "r":
                            // support this
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
		}

		private static void startVisualizer(string pathToController) {
			visualizerThread = new System.Threading.Thread(delegate() {
				visualizer = new Visualizer(pathToController);
				System.Windows.Forms.Application.Run(visualizer);
			});
			visualizerThread.Start();
		}

		private static void trace(params object[] list) {
			foreach( object o in list ) {
				try {
					Console.WriteLine(o.ToString() + ", ");
				} catch( Exception e ) {
					Console.WriteLine(e.Message + ", ");
				}				
			}
		}
	}
}
